//    Copyright (C) Clear Office.  All rights reserved.
using System;
using System.Collections.Generic;
using Office.Core.Serialization;

namespace Office.Spreadsheet.PivotTable
{
    class PivotCacheRecords: IOfficeXmlSerializable
    {
        private List<Record> _records = new List<Record>();
        private ExtensionList _extLst;

        #region IOfficeXmlSerializable Members

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read("pivotCacheRecords"))
            {
                _records.Clear();
                _records.AddRange(c.ReadOptionalWhile<Record>(Record.xmlName));
                _extLst = c.ReadOptionalElement<ExtensionList>("extLst");
                
            }
        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write("pivotCacheRecords"))
            {
                c.SetInteger("count", _records.Count);
                c.WriteElements(_records);
                c.WriteOptionalElement(_extLst);

            }
        }

        #endregion
    }
}
